package br.puc.paa.graph.model;


// Basic node stored in AVL trees
// Note that this class is not accessible outside
// of package DataStructures

public class AvlNode implements Comparable<AvlNode>
{
	
        // Constructors
    public AvlNode( Integer theElement , Vertice vertice)
    {
        this( theElement, vertice, null, null );
    }

    public AvlNode( Integer theElement, Vertice vertice, AvlNode lt, AvlNode rt )
    {
        element  = theElement;
        this.vertice = vertice;
        left     = lt;
        right    = rt;
        height   = 0;
    }

        // Friendly data; accessible by other package routines
    public Integer element;      // The data in the node
    public AvlNode    left;         // Left child
    public AvlNode    right;        // Right child
    public int        height;       // Height
    public Vertice vertice;
    
    public int getDistancia() {
    	return element.intValue();
    }
    
    public Vertice getVertice() {
    	return vertice;
    }

	@Override
	public int compareTo(AvlNode o) {
		if (this.element.equals(o.element) && this.vertice.equals(o.vertice)) return 0;
		else if (this.element.equals(o.element) && !this.vertice.equals(o.vertice))
			return this.vertice.compareTo(o.vertice);
		else return this.element.compareTo(o.element);
	}
	
	@Override
	public boolean equals(Object obj) {
		AvlNode node = (AvlNode) obj; 
		
		return this.element.equals(node.element) && this.vertice.equals(node.vertice);
	}
	
	@Override
	public String toString() {
		return "d=" + element + ", v=" + vertice + "";
	}
    
    
}